﻿/*Page created by Mike Beck -- holds the information for updating the info on SubmittedRecipes page*/

using System;
using Microsoft.Practices.ObjectBuilder;
using Common;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Linq;

namespace CSC440TeamOne.Admin.Views
{
	public partial class SubmittedRecipes : Microsoft.Practices.CompositeWeb.Web.UI.Page, ISubmittedRecipesView
	{
		private SubmittedRecipesPresenter _presenter;

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!this.IsPostBack)
			{
				this._presenter.OnViewInitialized();
			}
			this._presenter.OnViewLoaded();
		}

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            repRecipes.ItemDataBound += new RepeaterItemEventHandler(repRecipes_ItemDataBound);
        }

        void repRecipes_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            ControlBinder<RepeaterItem, Recipe>.Bind(e.Item, a =>
            {
                a.Find<HyperLink>("hyAcceptRecipe").Text = a.BusinessItem.name;
                a.Find<HyperLink>("hyAcceptRecipe").NavigateUrl = "VerifyRecipe.aspx?Recipe="+a.BusinessItem.RecipeID;

            });
        }

		[CreateNew]
		public SubmittedRecipesPresenter Presenter
		{
			get
			{
				return this._presenter;
			}
			set
			{
				if(value == null)
					throw new ArgumentNullException("value");

				this._presenter = value;
				this._presenter.View = this;
			}
		}

		// TODO: Forward events to the presenter and show state to the user.
		// For examples of this, see the View-Presenter (with Application Controller) QuickStart:
		//	


        public void show(SubmittedRecipesModel Model)
        {
            List<Recipe> recipes = Model.recipes;
            if (recipes.Any())
            {
                repRecipes.DataSource = recipes;
                repRecipes.DataBind();
            }
        }
    }
}

